<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	if($_RQ['merchid']){
		$_SESSION['merchid']=$_RQ['merchid'];
	}
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','',$_SESSION['merchid'],true);
	$return['pluginset']['merchfooternav']=$this->model('diy')->merchfooternav($_SESSION['merchid'],$return['pluginset']);
	$return['item']=$this->model('member')->getdetail($_SESSION['merchid']);
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$return['member']['sn']='NO'.sprintf("%09d", $_SESSION['uid']);
	$level= pdo_getcolumn('jy_weishop_member',array('merchid'=>$_SESSION['merchid'],'mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']),'level');
	$return['member']['leveltitle']= pdo_getcolumn('jy_weishop_member_level',array('id'=>$level, 'uniacid' => $_SESSION['uniacid']),'title');
	$return['merch']= pdo_get('jy_merch_user',array('id'=>$_SESSION['merchid'], 'uniacid' => $_SESSION['uniacid']),array('id','merchname','mobile'));
	$return['ideal_money']=pdo_getcolumn('core_ideal_money',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'money');
	$credit_types=credit_types();
	$credit_types2=array();
	foreach($credit_types as $key=>$value){
		$fee=$item['credit'.$key];
		$credit_types2[$key]=array(
			'id'=>$key,
			'title'=>$value,
			'fee'=>$fee
		);
	}
	$return['credit_types']=$credit_types2;
	$return['params']['type']=$_RQ['type']?:2;
	$return['feeurl']=$this->setting['feeurl'];
	$status0 = pdo_count('jy_weishop_order',array('merchid'=>$_SESSION['merchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>0,'deleted'=>0,'userdeleted'=>0));
	$status1 = pdo_count('jy_weishop_order',array('merchid'=>$_SESSION['merchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1,'deleted'=>0,'userdeleted'=>0));
	$status2 = pdo_count('jy_weishop_order',array('merchid'=>$_SESSION['merchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>2,'deleted'=>0,'userdeleted'=>0));
	$status3 = pdo_count('jy_weishop_order',array('merchid'=>$_SESSION['merchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>3,'iscomment'=>0,'deleted'=>0,'userdeleted'=>0));
	$cartnums= pdo_getsum('jy_weishop_member_cart',array('merchid'=>$_SESSION['merchid'],'mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']),'total');
	$return['statics']=array(
		'status0'=>$status0,
		'status1'=>$status1,
		'status2'=>$status2,
		'status3'=>$status3,
		'cartnums'=>$cartnums
	);
	set_html('title','会员中心');
	exi($return);
}
if($_RQ['op']=='post'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$post=get_postdata();
	if(!$post['fee']){
		exi('请输入转账金额！','erroe');
	}
	if(!$post['mobile']){
		exi('请输入收款人账户/手机号！','erroe');
	}
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	if($post['password']!=$member['paypassword']){
		exi('支付密码不正确！','erroe');
	}
	if($member['credit2']<$post['fee']){
		exi('转账额度不能大于，当前余额！','erroe');
	}
	$tomember=pdo_get('core_members',array('username'=>$post['mobile']));
	$tomid=$tomember['id'];
	if(!$tomid){
		$tomember=pdo_get('core_members',array('mobile'=>$post['mobile']));
		$tomid=$tomember['onemid']?:$tomember['id'];
	}
	if(!$tomid){
		exi('没找到收款人，转账失败！','erroe');
	}
	model('core/member')->cut_credit2($_SESSION['uid'],$post['fee'],'转账给:'.$post['mobile']);
	model('core/member')->add_credit2($tomid,$post['fee'],$member['username'].'的转账');
	exi('转账成功！');
}
if($_RQ['op']=='password'){
	$post=get_postdata();
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	pdo_update('core_members',array('paypassword'=>$post['password']),array('id'=>$_SESSION['uid']));
	exi('设置成功！');
}
if($_RQ['op']=='postmobile'){
	$postdata=get_postdata();
	if(strlen($postdata['mobile'])!=11 || $postdata['mobile'][0]!='1' || !is_numeric($postdata['mobile'])){
		exi('手机号码格式错误，请输入11位，1开头的手机号！！','error');
	}
	if(!check_sms_code($postdata['sms_code'])){
		exi('手机验证码错误！','error');
	}
	$check=pdo_get('jy_merch_member',array('mobile'=>$postdata['mobile'],'merchid'=>$_SESSION['merchid'],'mid <>'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($check['id']){
		exi('该手机号已经存在，已绑定别的账户！！','error');
	}
	$fields=array('mobile','realmobile');
	$postdata['realmobile']=$postdata['mobile'];
	$data=array_fields($fields,$postdata);
	$_SESSION['member']['mobile']=$postdata['mobile'];
	pdo_update('jy_merch_member',array('mobile'=>$postdata['mobile']),array('mid'=>$_SESSION['uid'],'merchid'=>$_SESSION['merchid'],'uniacid'=>$_SESSION['uniacid']));
	pdo_update('core_members',array('mobile'=>$postdata['mobile']),array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	/*$mid=model('core/member')->merge_memberdata($postdata['mobile']);
	if($_SESSION['uid']!=$mid){
		model('core/member')->login($mid);
		exi('设置成功！登录已绑定本手机的会员！');
	}*/
	exi('设置成功！');
}